home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 47.7z / BS1 part 47 / ImageMaster RT v1.50b (1994)(Black Belt Systems)(Disk 6 of 7)[HD].7z / ImageMaster RT v1.50b (1994)(Black Belt Systems)(Disk 6 of 7)[HD].adf / piarc.lzh.parta / nbkr.rexx < prev    next >
OS/2 REXX Batch file  |  1994-03-17  |  5KB  |  213 lines

  1. /*
  2.  * nbkr.rexx
  3.  *
  4.  *  Written by: Pete Patterson & Ben Williams
  5.  * Last Update: March 17, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.02
  9.  */
  10. parse arg '"' fullname '"'
  11. call pragma('stack',20000);
  12.  
  13. /*
  14.  * open rexxsupport.library -- needed for some functions
  15.  */
  16. if ~show('L',"rexxsupport.library") then do
  17.   if addlib('rexxsupport.library',0,-30,0) then do
  18.       /* everything's ok */
  19.     end;
  20.   else do
  21.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  22.     say 'Cannot operate nbkr.rexx without this library - sorry!';
  23.     exit 10;
  24.     end;
  25.   end;
  26.  
  27. prtnme = 'IM_Port'; /* assume Image Professional */
  28.  
  29.   /*
  30.    * This code attempts to read a file called "picmdpath" from REXX:
  31.    * If it can't find it, the script will assume that the commands
  32.    * associated with this PI Module are in "c:". If the file exists,
  33.    * the script will look in the path that is specified in the file.
  34.    * If you create this file, you MUST put a complete, correct path
  35.    * in it; if the commands are in a sub-directory, you have to put
  36.    * the trailing slash on the path (like, device:dir/).
  37.    * 
  38.    */
  39.   cmdpath = 'c:';
  40.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  41.     do
  42.       cmdpath = readln(fhandle);
  43.       call close(fhandle);  /* close the file    */
  44.     end
  45.  
  46. options;
  47. address;
  48.  
  49. if fullname = "" then do
  50.   prevpath = 'ram:'; /* put user in ram to start with... */
  51.  
  52.   if show('C',nbkpath) = 1 then do
  53.     prevpath = getclip(nbkpath);
  54.     end;
  55.  
  56.   address(prtnme);
  57.   options results;
  58.   'current';
  59.   bufdata = result; /* get name of buffer, if there is one */
  60.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  61.   if bname ~= '<none>' then do
  62.     bufname = bname;
  63.     end;
  64.   if (length(bufname) > 3) then do
  65.     epos = pos('.pg',bufname,length(bufname)-3);
  66.     if epos ~= 0 then do
  67.       bufname = left(bufname,epos-1)
  68.       end
  69.     end;
  70.   'filerequest "'||prevpath||'","'||bufname||'",".pg","Load NBOOK"';
  71.   nbkfile = result;
  72.   options;
  73.  
  74.   if nbkfile = 'FR_CANCELLED' then do
  75.     address(prtnme);
  76.     'imtofront';
  77.     'finish';
  78.     exit 0;
  79.     end;
  80.  
  81.   nbkfile = expandfilename(nbkfile);
  82.   thispath = gimmepath(nbkfile);
  83.   call setclip(nbkpath,thispath);
  84. end;
  85. else do
  86.   nbkfile = fullname;
  87.   thispath = gimmepath(nbkfile);
  88. end;
  89.  
  90.   address command cmdpath||'nbkrd c "'||nbkfile||'"';
  91.   if rc ~= 0 then do
  92.     address(prtnme);
  93.     'message "Cannot read '||nbkfile||'"';
  94.     'finish';
  95.     exit 0; /* this is not a proper nbk file */
  96.     end;
  97.  
  98.   call open(fhandle,'ram:IP_LDTRG.tmp','read');      /* open the file */
  99.   rstring = readln(fhandle);
  100.   call close(fhandle);                     /* close the file    */
  101.   
  102.   address command 'c:delete >nil: ram:IP_LDTRG.tmp';
  103.   
  104.   parse var rstring width '/' height
  105.  
  106.   if height < 0 then do
  107.     'message "Bad Height: '||height||'"';
  108.     'finish';
  109.     exit 0;
  110.     end;
  111.  
  112.   if height > 32767 then do
  113.     'message "Bad Height: '||height||'"';
  114.     'finish';
  115.     exit 0;
  116.     end;
  117.  
  118.   if width < 0 then do
  119.     'message "Bad Width: '||width||'"';
  120.     'finish';
  121.     exit 0;
  122.     end;
  123.  
  124.   if width > 32767 then do
  125.     'message "Bad Width: '||width||'"';
  126.     'finish';
  127.     exit 0;
  128.     end;
  129.  
  130.   address(prtnme);
  131.   
  132.   'imtofront'; /* show user the IM screen */
  133.   'newtargetted '||width||' '||height||' "'||gxname||'"'
  134.   if rc ~= 0 then do
  135.     options;
  136.     "message Can't allocate buffer, error #"||rc;
  137.     'autoredraw 1';
  138.     'finish';
  139.     exit 0;
  140.     end
  141.   bnum = result;
  142.  
  143.   address(prtnme);
  144.   options results;
  145.   'backin '||bnum;
  146.   jackadr = result;
  147.   options;
  148.  
  149.   'wbtofront';
  150.   'lockimage '||bnum;
  151.   address command cmdpath||'nbkrd d'||jackadr||' "'||nbkfile||'"';
  152.   'unlockimage '||bnum;
  153.  
  154.   address(prtnme);
  155.   'imtofront';
  156.   'autoredraw 1';
  157.   'finish';
  158.   address;
  159.  
  160.   exit 0;
  161.  
  162. /*
  163.  * gimmepath
  164.  *
  165.  * This takes the provided argument and sucks the path out of it, then
  166.  * returns that path to the caller, sans file name.
  167.  */
  168. gimmepath:
  169.   arg fullnamegx;
  170.     tempgx = reverse(fullnamegx);
  171.     lengx = length(fullnamegx);   /* get length of string */
  172.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  173.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  174.     seploc = 0; /* assumes current dir, no path supplied */
  175.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  176.       seploc = (lengx - slashdex)+1;
  177.       end;
  178.     else do
  179.       if colondex ~= 0 then do /* we assume we are on a device */
  180.         seploc = (lengx - colondex)+1;
  181.         end;
  182.       end;
  183.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  184.   gxpath = left(fullnamegx,seploc);
  185.   return(gxpath);
  186.  
  187. /*
  188.  * Since this script can't be expected to know where the CD of the user
  189.  * is when this cmd is invoked, we have to check the path the user
  190.  * provides - if it's not specified right from a root, then we have
  191.  * to make it a complete specification from the root.
  192.  */
  193. expandfilename:
  194.   parse arg jfile;
  195.   if index(jfile,':') = 0 then do
  196.     curdir = pragma(D);
  197.     if right(curdir,1) ~= ':' then do
  198.       if right(curdir,1) ~= '/' then do
  199.         if curdir ~= '' then do
  200.           curdir = curdir || '/';
  201.           end;
  202.         end;
  203.       end;
  204.     jfile = curdir||jfile;
  205.     end;
  206.   return(jfile);
  207.  
  208. rvalue:
  209.   wordnum = c2d(readch(fhandle,1)) * 256;
  210.   wordnum = wordnum + c2d(readch(fhandle,1));
  211.   return wordnum;
  212.  
  213.